import React from 'react';
import { Button } from 'antd';
import Authorized from '@/utils/Authorized';
import PropTypes from 'prop-types';

const Authority = props => {
  const { authority, onClick, title, style, type, children } = props;
  return (
    <Authorized authority={authority} noMatch={null}>
      <Button type={type} style={style} onClick={onClick}>
        {children}
        {title}
      </Button>
    </Authorized>
  );
};

Authority.propTypes = {
  authority: PropTypes.string.isRequired,
  onClick: PropTypes.func.isRequired,
  title: PropTypes.string.isRequired,
  style: PropTypes.object,
  type: PropTypes.string,
  children: PropTypes.node,
};

Authority.defaultProps = {
  style: null,
  type: 'default',
  children: null,
};

export default React.memo(Authority);
